<?php
class WallController extends MainController implements ControllerInterface {

	//o - order
	//v - order vector
	//t - total items to select
	public $tableConfig = array(
		'wall_table' => array(
			'o' => array(
				'id' => 'usera_wall.id_users_wall',
				'entry' => 'users_wall.description',
				'date' => 'users_wall.date',
				'_' => 'date'
			),
			'v' => 'malejaco',
			't' => 25
		)
	);

	public function preDispatch($param) {
		$this->Run($param);
		$this->RunShared('Auth', array());
	}

	public function postDispatch($param) {
		
	}

	public function IndexAction($param){
		$dal = UsersWallDAL::GetDalDataObj(array(
			'tableData' => $this->tableParams['wall_table'],
			'condition' => array(
				'id_user' => array(array('condition' => ' IS NULL ','value' => '')),
				'global_users' => 1
			)
		));

		$list = UsersWallDAL::GetResult($dal);
		$dal->setCount(true);
		$dal->setLimit('');
		$count = UsersWallDAL::GetResult($dal);

		$this->smarty->assign('list',$list);
		$this->smarty->assign('c',$count);
	}

	public function EditAction($param) {

		if(!isset($param['id'])) {
			$usersWall = new UsersWall();
			$usersWall->setIdUser('NULL');
		}else{
			$usersWall = array_pop(UsersWallDAL::GetResult(UsersWallDAL::GetDalDataObj(array('limit' => 1,'condition' => array('id_users_wall' => $param['id'])))));
			$usersWall->setIdUser(null);
		}
		
		if(Request::IsPost()) {
			
			$usersWall->setDate(date('Y-m-d G:i:s'));
			$usersWall->setGlobalUsers(1);
			$usersWall->setDescription(Request::GetPost('description',false, false));

			UsersWallDAL::Save($usersWall->getDalDataObj());

			$this->AddRedirect(Router::GenerateUrl('wallIndex',array('wall' => 'index')),0);
		}

		$this->smarty->assign('obj',$usersWall);
	}

	public function getMainClassName() {
		return 'UsersWall';
	}
}